<?php

function saveScore($dat){
	$idx = $dat['index'];
	$uid = empty($dat['uid'])?session('uid'):$dat['uid'];
	$data = array();
	$data['g'.$idx.'_value'] = empty($dat['value'])?'':$dat['value'];
	$data['g'.$idx.'_score'] = empty($dat['score'])?0:$dat['score'];
	$data['g'.$idx.'_created'] = date('Y-m-d H:i:s');
	$data['g'.$idx.'_status'] = 1;
	$data['uid'] = $uid;
	
	$row = M('Score')->where('uid='.$uid)->find();
	if(empty($row)){
		$rs = M('Score')->data($data)->add();
	}else{
		$rs = M('Score')->where('uid='.$uid)->save($data);
	}
}

?>